<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <!-- 满足有些用户在手机端访问的需要 -->

    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">

    <title>用户管理</title>
    <!-- 线上环境 -->
    <link rel="stylesheet" href="/static/css/dist/component-min.css">
    <link rel="stylesheet" href="/static/plugins/jbox/jbox-min.css">

    <!--vue-->
    <script src="/static/vue/vue.js"></script>
    <!--element ui-->
    <script src="/static/element/index.js"></script>
    <link rel="stylesheet" href="/static/element/index.css">
    <style>
        .el-table__empty-block {
            height: 0;
        }
    </style>

</head>
<body class="cp-bodybox">
<div id="app">
    <#include "/common/header-fg.html" />

    <div class="container">
        <div class="inner clearfix">
            <#include "/common/left-menu-fg.html" />

            <div class="content-right">
                <h1 class="content-right-title">订单退款待办</h1>
                <div>
                    <el-card class="box-card">
                        <el-form :inline="true" ref="search" :model="search" label-width="80px">
                            <el-row>
                                <el-col :span="8">
                                    <el-form-item label="客户搜索">
                                        <el-input v-model="search.keyword" placeholder="昵称/手机号"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="申请时间">
                                        <el-date-picker
                                                v-model="search.applyTimeStart"
                                                type="date"
                                                placeholder="选择日期">
                                        </el-date-picker>&nbsp;至&nbsp;
                                        <el-date-picker
                                                v-model="search.applyTimeEnd"
                                                type="date"
                                                placeholder="选择日期">
                                        </el-date-picker>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="退款状态">
                                        <el-select v-model="search.status" placeholder="请选择状态">
                                            <!--<el-option value="-1" label="拒绝"></el-option>-->
                                            <el-option value="1" label="待商家审核"></el-option>
                                            <el-option value="2" label="待财务审核"></el-option>
                                            <el-option value="3" label="待运营审核"></el-option>
                                            <el-option value="4" label="待确认退款"></el-option>
                                            <!--<el-option value="5" label="完成"></el-option>-->
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24" >
                                    <div style="float: right">
                                        <el-button type="primary" @click.native.prevent="getList">查询</el-button>
                                        <el-button @click.native.prevent="clearSearch">清空查询</el-button>
                                    </div>
                                </el-col>
                            </el-row>
                        </el-form>
                    </el-card>
                    <el-card class="box-card" style="margin-top: 10px">
                        <el-table
                                :data="list"
                                border
                                style="width: 100%">
                            <el-table-column
                                    type="index"
                                    label="行号"
                                    width="80">
                            </el-table-column>
                            <el-table-column
                                    prop="orderCode"
                                    label="订单号"
                                    width="210">
                            </el-table-column>
                            <el-table-column
                                    prop="itemName"
                                    label="商品名称">
                            </el-table-column>
                            <el-table-column
                                    prop="orgName"
                                    label="商家">
                            </el-table-column>
                            <el-table-column
                                    prop="customerNick"
                                    show-overflow-tooltip
                                    label="客户昵称">
                            </el-table-column>
                            <el-table-column
                                    prop="customerTel"
                                    label="手机号">
                            </el-table-column>
                            <el-table-column
                                    prop="applyTime"
                                    align="center"
                                    :formatter="formatterTime"
                                    width="130"
                                    label="申请时间">
                            </el-table-column>
                            <el-table-column
                                    prop="refundReason"
                                    show-overflow-tooltip
                                    label="退款原因">
                            </el-table-column>
                            <el-table-column
                                    prop="realPayAmount"
                                    label="交易金额(元)">
                            </el-table-column>
                            <el-table-column
                                    prop="refundAmount"
                                    label="退款金额(元)">
                            </el-table-column>
                            <el-table-column
                                    prop="state"
                                    label="退款状态"
                                    :formatter="formatterStatus">
                            </el-table-column>
                            <el-table-column
                                    align="center"
                                    label="操作"
                                    inline-template>
                                <div style="margin-left: -10px">
                                    <template v-if="row.status !== -1 && row.status !== 5">
                                        <el-dropdown>
                                            <el-button size="small" type="primary">
                                                操作<i class="el-icon-caret-bottom el-icon--right"></i>
                                            </el-button>
                                            <el-dropdown-menu slot="dropdown" align="center">
                                                <el-dropdown-item v-if="row.status === 1 && isPermission('refund:orgCheck', user.permissions)"><el-button size="small" type="primary" @click.native.prevent="showCheckDialog(row, false)">商家审核</el-button></el-dropdown-item>
                                                <el-dropdown-item v-if="row.status === 2 && isPermission('refund:financeCheck', user.permissions)"><el-button size="small" type="primary" @click.native.prevent="showCheckDialog(row, false)">财务审核</el-button></el-dropdown-item>
                                                <el-dropdown-item v-if="row.status === 3 && isPermission('refund:operatorCheck', user.permissions)"><el-button size="small" type="primary" @click.native.prevent="showCheckDialog(row, false)">运营审核</el-button></el-dropdown-item>
                                                <el-dropdown-item v-if="row.status !== 1 && isPermission('refund:checkView', user.permissions)"><el-button size="small" type="primary" @click.native.prevent="showCheckDialog(row, true)">审核记录</el-button></el-dropdown-item>
                                                <el-dropdown-item v-if="row.status === 4 && isPermission('refund:confirm', user.permissions)"><el-button size="small" type="primary" @click.native.prevent="confirmDoRefund(row.id)">确认退款</el-button></el-dropdown-item>
                                            </el-dropdown-menu>
                                        </el-dropdown>
                                    </template>
                                </div>
                            </el-table-column>
                        </el-table>
                        <el-pagination
                                @current-change="handleCurrentPageChange"
                                :current-page="currentPage"
                                :page-size="pageSize"
                                layout="total, prev, pager, next"
                                :total="totalCount"
                                style="margin-top: 10px">
                        </el-pagination>
                    </el-card>
                </div>
            </div>

            <yiqi-examine :readonly="checkReadOnly" title="退款审核" :only-history="checkOnlyHistory" :type-id="1" :history-result="checkRecordList" ref="examineDialog" :examine-dialog="checkDialog" :readonly="false" :is-item="false"
                          :result="checkResult" :desc="checkDesc"
                          :save-callback="saveCallback" :cancel-callback="cancelCallback">
            </yiqi-examine>
            <a href="javascript:;" class="btn-leftMenuFold" id="j-btn-leftMenuFold"></a>
        </div>
    </div>
    <!-- end container -->

    <!--gonggao-->

    <!--tip-->
    <div class="footer">© 2017 , Inc. All rights reserved.</div>
    <!-- end footer -->
    <div class="fixedBar" style="right: -78px;">
        <ul>
            <template v-for="(item, index) in leftMenuList">
                <li v-if="index==0" :class="'shopManager' + index + ' cur'"><a href="javascript:;" :data-target="'#shop_' + index">{{item.groupName}}</a></li>
                <li v-else :class="'shopManager' + index"><a href="javascript:;" :data-target="'#shop_' + index">{{item.groupName}}</a></li>
            </template>
        </ul>
        <a href="javascript:;" class="fixedBar-btn" id="j-fixedBar-btn"></a>
    </div>
    <a href="#" id="j-gotop" class="gotop" title="回到顶部" style="left: 1920.59px;"></a>

</div>
<script src="/static/js/dist/lib-min.js"></script>
<script src="/static/js/dist/list.js"></script>
<script src="/static/js/dist/component-min.js"></script>

<!-- 引入api -->
<script src="/static/js/api.js"></script>
<script src="/static/js/common.js?v=8"></script>
<script>
    new Vue({
        el: '#app',
        mounted:function () {
            this.getList ();
        },
        data: function(){
            return {
                user: ${(user)!'null'},
                checkDialog: false,
                checkOnlyHistory: false,
                checkReadOnly: false,
                checkResult: 1,
                checkDesc: '',
                checkRecordList: [],
                checkForm: {
                    resource: ''
                },
                checkRecord: {},
                value:'',
                search: {
                    keyword: '',
                    applyTimeStart:'',
                    applyTimeEnd: '',
                    status: ''
                },
                list: [],
                currentPage: list.currentPage,
                pageSize: list.pageSize,
                totalCount: 0,
                headerNavList: list.headerNavList,
                accountNavList: list.accountNavList,
                leftMenuList: list.menu
            }
        },
        methods: {
            doRefund (id) {
                let that = this;
                let loading = this.$loading({fullscreen: true, lock: true});
                this.http("/order/refund/confirm", {id: id}, function (res) {
                    if (res.status === 200) {
                        loading.close();
                        that.getList();
                        that.$alert('退款成功','提示',{
                            confirmButtonText:'确定',
                        })
                    } else {
                        loading.close();
                        that.$alert(res.errMsg, '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    loading.close();
                    that.$alert('退款失败','提示',{
                        confirmButtonText:'确定',
                    })
                })
            },
            confirmDoRefund (id) {
                let that = this;
                this.$confirm('确认执行退款操作?, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {
                    that.doRefund(id);
                }).catch(function () {
                    that.$message({
                        type: 'info',
                        message: '已取消下架'
                    });
                });
            },
            saveCallback () {
                let result = this.$refs.examineDialog.examineForm.result;
                let desc = this.$refs.examineDialog.examineForm.desc;
                let checkedList = this.$refs.examineDialog.checkTag;
                let check = {
                    refundId: this.checkRecord.id,
                    status: this.checkRecord.status,
                    result: result
                }
                if (result === 0) {
                    let msg = ''
                    if (checkedList.length > 0) {
                        for (let i=0; i<checkedList.length; i++) {
                            if (msg !== '') {
                                msg += ';'
                            }
                            msg += checkedList[i]
                        }
                    }
                    if (desc !== '') {
                        if (msg !== '') {
                            msg += ';'
                        }
                        msg += desc
                    }
                    check.desc = msg
                }
                let that = this
                let loading = this.$loading({fullscreen: true, lock: true, text: '加载中'});
                let url = ''
                if (this.checkRecord.status === 1) {
                    url = '/order/refund/check/org'
                } else if (this.checkRecord.status === 2) {
                    url = '/order/refund/check/finance'
                } else if (this.checkRecord.status === 3) {
                    url = '/order/refund/check/operator'
                }
                this.http(url,check,function (res) {
                    if(res.status === 200){
                        that.$alert('审核成功','提示',{
                            confirmButtonText:'确定',
                        })
                        loading.close();
                        that.checkDialog = false;
                        that.getList()
                    }else{
                        loading.close();
                        that.$alert(res.errMsg,'提示',{
                            confirmButtonText:'确定',
                        })
                    }
                },function (res) {
                    loading.close();
                    that.$alert('服务器错误','提示',{
                        confirmButtonText:'确定',
                    })
                })
            },
            cancelCallback () {
                this.checkDialog = false;
            },
            formatterTime (row, column) {
                if (row.applyTime !== undefined && (row.applyTime + "").length >= 10) {
                    return (row.applyTime + "").substring(0, 10);
                } else {
                    return row.applyTime;
                }
            },
            showCheckDialog(row, type){
                this.checkRecord = row;
                let that = this
                this.$get('/order/refund/logList?refundId=' + row.id, null,function (res) {
                    if(res.status === 200){
                        let logList = res.returnValue;
                        that.checkRecordList = []
                        for (let i=0; i<logList.length; i++) {
                            let obj = {}
                            if (logList[i].status === 1) {
                                obj.header = '商家审核'
                            } else if (logList[i].status === 2) {
                                obj.header = '财务审核'
                            } else if (logList[i].status === 3) {
                                obj.header = '运营审核'
                            }
                            obj.user = logList[i].operator
                            obj.createTime = logList[i].operateTime
                            if (logList[i].result === 1) {
                                obj.result = '通过'
                            } else {
                                obj.result = '不通过（' + logList[i].desc + '）'
                            }
                            that.checkRecordList.push(obj)
                        }
                        that.checkDialog = true
                        that.checkOnlyHistory = type
                        that.checkReadOnly = type
                        if(that.checkRecord.checkResult !== undefined && that.checkRecord.checkResult !== null){
                            that.flag = true;
                            that.checkForm.resource = that.checkRecord.checkResult;
                            that.checkForm.spreadSale = that.checkRecord.spreadSale;
                        }else{
                            that.flag = false;
                        }
                    }else{
                        that.$alert(res.errMsg,'提示',{
                            confirmButtonText:'确定',
                        })
                    }
                },function (res) {
                    that.$alert('服务器错误','提示',{
                        confirmButtonText:'确定',
                    })
                })
            },
            formatterStatus(row){
                if (row.status === -1) {
                    return '拒绝'
                } else if (row.status === 1) {
                    return '待商家审核'
                } else if (row.status === 2) {
                    return '待财务审核'
                } else if (row.status === 3) {
                    return '待运营审核'
                } else if (row.status === 4) {
                    return '待确认退款'
                } else if (row.status === 5) {
                    return '完成'
                }
            },
            handleCurrentPageChange(val) {
                this.currentPage = val
                this.getList()
            },
            getList () {
                let that = this
                let obj = {}
                obj.currentPage = this.currentPage
                obj.pageSize = this.pageSize
                if (this.search.status != '') {
                    obj.status = this.search.status
                }
                if (this.search.applyTimeStart != '') {
                    obj.applyTimeStart = this.formatTime(this.search.applyTimeStart, true)
                }
                if (this.search.applyTimeEnd != '') {
                    obj.applyTimeEnd = this.formatTime(this.search.applyTimeEnd, true)
                }
                obj.keyword = this.search.keyword;
                let loading = this.$loading({fullscreen: true, lock: true, text: '加载中'});
                this.http('/order/refund/list',obj,function (res) {
                    if(res.status === 200){
                        that.list = res.data.list;
                        that.totalCount = res.data.total;
                        loading.close();
                    }else{
                        loading.close();
                        that.$alert(res.errMsg,'提示',{
                            confirmButtonText:'确定',
                        })
                    }
                },function (res) {
                    loading.close();
                    that.$alert('服务器错误','提示',{
                        confirmButtonText:'确定',
                    })
                })
            },
            clearSearch () {
                this.search.status = ''
                this.search.keyword = ''
                this.search.applyTimeStart = ''
                this.search.applyTimeEnd = ''
                this.currentPage = 1
                this.getList()
            }
        }
    })
</script>

<!-- 20170105 --></body>
</html>